import java.util.Scanner;

public class Main1232 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        int min = arr[0];
        int max = arr[0];
        for (int i = 0; i < n; i++) {
            if (arr[i] < min) {
                min = arr[i];
            }
            if (arr[i] > max) {
                max = arr[i];
            }
        }
        int a=0;
        int b=0;
        for (int i=0;i<n;i++){
            if (arr[i]==max){
                a=i;
            }
            if (arr[i]==min){
                b=i;
            }
        }arr[a]=min;
        arr[b]=max;
        for (int i=0;i<n;i++){
            System.out.print(arr[i]+" ");
        }
    }
}
